/*
 * @Author: your name
 * @Date: 2021-06-01 14:22:33
 * @LastEditTime: 2021-06-13 21:55:32
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \finalHWTSU\main.cpp
 */
#include <iostream>
#include "src/LCD.h"
#include "src/Counter.h"
#include <Windows.h>
#include "stdlib.h"
using namespace std;
int main(int, char **)
{
  // clear the screen
  system("mode con cols=200 lines=45"); // set the screen to 200*45
  LCD lcd;
  char inputStr[10]; //为了节省资源，这里设置了十个字符，如果输入过长的字符会报错！
  Counter ct(&lcd);
  while (1)
  {
    system("cls");
    lcd.vInputMask();
    Sleep(1000);
    system("cls");
    lcd.vAfterInputMask2();
    Sleep(1000);
    cin >> inputStr;
    int input;
    while (!ct.bInputIsRight(inputStr))
    {

      lcd.ErrorHandle();
      cin.clear();
      while (cin.get() != '\n')
      {
        continue; // 清空缓冲区
      }
      system("cls");
      lcd.vAfterInputMask2();
      Sleep(1000);
      cin >> inputStr;
    }
    input = atoi(inputStr); //没有问题的字符转换成数字
    if (input > 0 && input <= 999)
    {
      ct.iSetTime(input+1);
      ct.vRun();
    }
    else if (input > 999)
    {
      ct.iSetTime(999);
      ct.vRun();
    }
    else if (input == -1)
    {
      break;
    }
    else
      lcd.ErrorHandle();
    system("cls");
    lcd.vAfterInputMask();
    Sleep(1000);
    // lcd.vAfterInputMask2();
    // Sleep(1000);
  }
  // lcd.vDisp()();
  return 0;
}
